<template>
  <div class="coverage">
    <div class="bg" :class="{ display: isDisplay }">
      <div class="logo">
        <img v-lazy="src" />
      </div>
      <div class="login">
        <router-link tag="p" :to="{ name: 'login' }">{{this.$store.state.username}}</router-link>
      </div>
    </div>

    <div class="my">
      <router-link tag="li" active-class="active" :to="{ name: 'myOrder' }"
        >我的订单</router-link
      >
      <router-link
        tag="li"
        active-class="active"
        :to="{ name: 'myAppointment' }"
        >我的预约</router-link
      >
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isDisplay: false,
      src:
        "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607083213927&di=2bfe8ce7a54af364e0579fca4bf66543&imgtype=0&src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20190825%2F15%2F1566718848-hXJsWotabw.jpeg",
    };
  },
  mounted() {
    //监听滚动
    window.addEventListener("scroll", (e) => {
      // 获取滚动条距离顶部高度
      let scrollTop = document.documentElement.scrollTop;
      // 根据滚动条高度来决定是否吸顶
      if (scrollTop >= 200) {
        this.isDisplay = true;
      } else {
        this.isDisplay = false;
      }
    });
  },
};
</script>

<style  lang = "scss" scoped>
.display {
  display: none;
}
.bg {
  width: 100%;
  height: 150px;
  background: white;
  overflow: hidden;
  .logo {
    width: 70px;
    height: 70px;
    background: white;
    border: 1px solid black;
    border-radius: 50%;
    margin: 0 auto;
    margin-top: 30px;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }
  .login {
    p {
      text-align: center;
      color: black;
      font-size: 16px;
    }
    margin-top: 10px;
  }
}
.my {
  z-index: 1;
  width: 100%;
  height: 40px;
  li {
    width: calc(50% - 2px);
    height: 40px;
    z-index: 2;
    background: white;
    border: 1px solid #cfcfcf;
    color: gray;
    text-align: center;
    line-height: 40px;
    float: left;
    &.active {
      color: #fe5100;
      font-weight: 600;
    }
  }
}
</style>